/*
 *  SyncIT , easy synchronization of files between computers and devices.
 *  Copyright (C) 2011  Christian Masus <cmasus(at)gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version. If redistributing and/or modifying
 *  this file, this notice must be included in the redistributed or
 *  modified copy.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package gui.javagui;

import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;

public class GuiActions {

	ActionInterface actionInterface;

	private Action addAction;
	private Action removeAction;
	private Action startAction;
	private Action pauseAction;
	private Action stopAction;
	private Action moveUpAction;
	private Action moveDownAction;
	private Action preferencesAction;
	private Action exitAction;

	private Action helpAction;
	private Action webpageAction;
	private Action whatIsMyIPAction;
	private Action checkforUpdatesAction;
	private Action aboutAction;

	public GuiActions(ActionInterface actionInterface) {
		this.actionInterface = actionInterface;

		addAction = new AddAction("Add", new ImageIcon("res/add.png"), "Add sync instance", KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK));
		removeAction = new RemoveAction("Remove", new ImageIcon("res/remove.png"), "Remove marked sync instances", KeyEvent.VK_R);
		startAction = new StartAction("Start", new ImageIcon("res/start.png"), "Start Sync", KeyEvent.VK_S, KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK));
		pauseAction = new PauseAction("Pause", new ImageIcon("res/pause.png"), "Pause Sync", KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_DOWN_MASK));
		stopAction = new StopAction("Stop", new ImageIcon("res/stop.png"), "Stop Sync", KeyEvent.VK_T, KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK));
		moveUpAction = new MoveUpAction("Move Up", new ImageIcon("res/move-up.png"), "Move Up Priority", KeyEvent.VK_U);
		moveDownAction = new MoveDownAction("Move Down", new ImageIcon("res/move-down.png"), "Move Down Priority", KeyEvent.VK_D);
		preferencesAction = new PreferencesAction("Preferences", new ImageIcon("res/preferences.png"), "Open Preferences", KeyEvent.VK_E, KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_DOWN_MASK));
		exitAction = new ExitAction("Exit", null, "Exit SyncIT", KeyEvent.VK_X);

		helpAction = new HelpAction("SyncIT Help", null, "Show SyncIT Help", KeyEvent.VK_H, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
		webpageAction = new WebpageAction("SyncIT Web page", null, "Open SyncIT Web page", KeyEvent.VK_W);
		whatIsMyIPAction = new WhatIsMyIPAction("What Is My IP", null, "Find out all your IPs", KeyEvent.VK_I);
		checkforUpdatesAction = new CheckForUpdatesAction("Check for Updates", null, "Check for Updates", KeyEvent.VK_C);
		aboutAction = new AboutAction("About SyncIT", null, "About SyncIT", KeyEvent.VK_B);
	}


	public Action getAddAction() {
		return addAction;
	}

	public Action getRemoveAction() {
		return removeAction;
	}

	public Action getStartAction() {
		return startAction;
	}

	public Action getPauseAction() {
		return pauseAction;
	}

	public Action getStopAction() {
		return stopAction;
	}

	public Action getMoveUpAction() {
		return moveUpAction;
	}

	public Action getMoveDownAction() {
		return moveDownAction;
	}

	public Action getPreferencesAction() {
		return preferencesAction;
	}

	public Action getExitAction() {
		return exitAction;
	}

	public Action getHelpAction() {
		return helpAction;
	}

	public Action getWebpageAction() {
		return webpageAction;
	}

	public Action getWhatIsMyIPAction() {
		return whatIsMyIPAction;
	}

	public Action getCheckforUpdatesAction() {
		return checkforUpdatesAction;
	}

	public Action getAboutAction() {
		return aboutAction;
	}



	public void enableRemoveAction(boolean enable) {
		removeAction.setEnabled(enable);
	}

	public void enableMoveUpAction(boolean enable) {
		moveUpAction.setEnabled(enable);
	}

	public void enableMoveDownAction(boolean enable) {
		moveDownAction.setEnabled(enable);
	}



	@SuppressWarnings("serial")
	class AddAction extends AbstractAction {
		public AddAction(String text, ImageIcon icon, String desc, Integer mnemonic, KeyStroke ks) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(ACCELERATOR_KEY, ks);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.addAction();
		}
	}

	@SuppressWarnings("serial")
	class RemoveAction extends AbstractAction {
		public RemoveAction(String text, ImageIcon icon, String desc, Integer mnemonic) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
			setEnabled(false);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.removeAction();
		}
	}

	@SuppressWarnings("serial")
	class StartAction extends AbstractAction {
		public StartAction(String text, ImageIcon icon, String desc, Integer mnemonic, KeyStroke ks) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(ACCELERATOR_KEY, ks);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.startAction();
		}
	}

	@SuppressWarnings("serial")
	class PauseAction extends AbstractAction {
		public PauseAction(String text, ImageIcon icon, String desc, Integer mnemonic, KeyStroke ks) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(ACCELERATOR_KEY, ks);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.pauseAction();
		}
	}

	@SuppressWarnings("serial")
	class StopAction extends AbstractAction {
		public StopAction(String text, ImageIcon icon, String desc, Integer mnemonic, KeyStroke ks) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(ACCELERATOR_KEY, ks);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.stopAction();
		}
	}

	@SuppressWarnings("serial")
	class MoveUpAction extends AbstractAction {
		public MoveUpAction(String text, ImageIcon icon, String desc, Integer mnemonic) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
			setEnabled(false);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.moveUpAction();
		}
	}

	@SuppressWarnings("serial")
	class MoveDownAction extends AbstractAction {
		public MoveDownAction(String text, ImageIcon icon, String desc, Integer mnemonic) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
			setEnabled(false);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.moveDownAction();
		}
	}

	@SuppressWarnings("serial")
	class PreferencesAction extends AbstractAction {
		public PreferencesAction(String text, ImageIcon icon, String desc, Integer mnemonic, KeyStroke ks) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(ACCELERATOR_KEY, ks);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.preferencesAction();
		}
	}

	@SuppressWarnings("serial")
	class ExitAction extends AbstractAction {
		public ExitAction(String text, ImageIcon icon, String desc, Integer mnemonic) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.exitAction();
		}
	}

	@SuppressWarnings("serial")
	class HelpAction extends AbstractAction {
		public HelpAction(String text, ImageIcon icon, String desc, Integer mnemonic, KeyStroke ks) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
			putValue(ACCELERATOR_KEY, ks);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.helpAction();
		}
	}

	@SuppressWarnings("serial")
	class WebpageAction extends AbstractAction {
		public WebpageAction(String text, ImageIcon icon, String desc, Integer mnemonic) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.webpageAction();
		}
	}

	@SuppressWarnings("serial")
	class WhatIsMyIPAction extends AbstractAction {
		public WhatIsMyIPAction(String text, ImageIcon icon, String desc, Integer mnemonic) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.whatIsMyIPAction();
		}
	}

	@SuppressWarnings("serial")
	class CheckForUpdatesAction extends AbstractAction {
		public CheckForUpdatesAction(String text, ImageIcon icon, String desc, Integer mnemonic) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.checkForUpdatesAction();
		}
	}

	@SuppressWarnings("serial")
	class AboutAction extends AbstractAction {
		public AboutAction(String text, ImageIcon icon, String desc, Integer mnemonic) {
			super(text, icon);
			putValue(SHORT_DESCRIPTION, desc);
			putValue(MNEMONIC_KEY, mnemonic);
		}
		public void actionPerformed(ActionEvent e) {
			actionInterface.aboutAction();
		}
	}

}
